/**
 * Project: topdt-jbpm
 * Copyright 2013  Top Digital Technology  Co. Ltd.
 * All right reserved.
 */
package com.topdt.jbpm.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/**
 * 建立日期 : 2013-4-12 下午3:58:02<br>
 * 作者 : balance<br>
 * 模块 : <br>
 * 描述 : <br>
 * 修改历史: 序号 日期 修改人 修改原因 <br>
 * 1 <br>
 * 2 <br>
 */
@Entity
@Table(name = "wf_application")
public class Application extends JbpmModel implements Comparable<Application> {

	private static final long serialVersionUID = 6255239393084189224L;

	public static final String APPATTR_FORM="0";
	public static final String APPATTR_DOC="1";
	public static final String APPATTR_CUSTOM_FORM = "2";
	public static final String APPATTR_CUSTOM_DOC = "3";
	public static final String APPATTR_CUSTOM_FORM_OPINION = "4";
	public static final String APPATTR_CUSTOM_DOC_OPINION = "5";
	
	public static final String SYSTEM_APP = "1";//系统默认应用
	public static final String NORMAL_APP = "0";//普通应用
	public static final String INVALID_APP = "0";//无效的应用
	public static final String VALID_APP = "1";//有效的应用
	public static final String NORMAL_HANDLE_ID = "1"; //通用的应用处理类的id为1，处理类为：com.topdt.jbpm.form.GeneralFormHandle
	@Id
	@GeneratedValue(generator = "generator")
	@GenericGenerator(name = "generator", strategy = "uuid")
	@Column(length = 32)
	private String appId;// 应用标示
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "appTypeId")
	private AppType appType;

	private String appName;

	private String appDescribe;

	private String flowId;// 流程Id

	private String flowKey;// 流程键值

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "formId")
	private Form form;// 表单对象

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "handleId")
	private AppHandle handle;

	
	private String isInherent="0";//--是否是系统默认的应用 0 表示不是默认的
	private String isValid="1";//-- 是否有效 1表示有效
	
	private String appAttr;//app的属性 0 是表单类的应用 1 是公文类的应用 2是自定义表单的应用
	private String docTempath;//公文模板Id
	
	private Date createTime;//创建时间
	private String selectFlowId;//用于页面显示的flowId
	
	private Long appOrder;//fengjinshou 20151229 应用顺序
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "appFormId")
	private AppForm appForm;
	
	private String isComplete ;//应用信息是否完整,1表示可用
	public String getDocTempath() {
		return docTempath;
	}

	public void setDocTempath(String docTempath) {
		this.docTempath = docTempath;
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}


	public String getAppName() {
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	public String getAppDescribe() {
		return appDescribe;
	}

	public void setAppDescribe(String appDescribe) {
		this.appDescribe = appDescribe;
	}

	public String getFlowId() {
		return flowId;
	}

	public void setFlowId(String flowId) {
		this.flowId = flowId;
	}

	public String getFlowKey() {
		return flowKey;
	}

	public void setFlowKey(String flowKey) {
		this.flowKey = flowKey;
	}

	public Form getForm() {
		return form;
	}

	public void setForm(Form form) {
		this.form = form;
	}

	public AppHandle getHandle() {
		return handle;
	}

	public void setHandle(AppHandle handle) {
		this.handle = handle;
	}


	public String getIsInherent() {
		return isInherent;
	}

	public void setIsInherent(String isInherent) {
		this.isInherent = isInherent;
	}

	public String getIsValid() {
		return isValid;
	}

	public void setIsValid(String isValid) {
		this.isValid = isValid;
	}

	public String getAppAttr() {
		return appAttr;
	}

	public void setAppAttr(String appAttr) {
		this.appAttr = appAttr;
	}
	public boolean isFreeFlow(){
		if((this.flowId==null||"".equals(this.flowId))&&(this.flowKey==null||"".equals(this.flowKey))){
			return true;
		}
		return false;
	}
	public AppForm getAppForm() {
		return appForm;
	}

	public void setAppForm(AppForm appForm) {
		this.appForm = appForm;
	}

	public AppType getAppType() {
		return appType;
	}

	public void setAppType(AppType appType) {
		this.appType = appType;
	}
    
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
    
	
	public String getSelectFlowId() {
		return selectFlowId;
	}

	public void setSelectFlowId(String selectFlowId) {
		this.selectFlowId = selectFlowId;
	}
    
	public String getIsComplete() {
		return isComplete;
	}

	public void setIsComplete(String isComplete) {
		this.isComplete = isComplete;
	}

	public Long getAppOrder() {
		return appOrder;
	}

	public void setAppOrder(Long appOrder) {
		this.appOrder = appOrder;
	}
	
	@Override
	public int compareTo(Application app) {
		//fengjinshou 20151230  重写 实现TreeSet按appOrder升序排序
		if(this.appOrder!=null && app.getAppOrder()!=null){
			if(this.appOrder.compareTo(app.getAppOrder())>0){
				return 1;
			}else if(this.appOrder.compareTo(app.getAppOrder())<0){
				return -1;
			}else{
				return 0;
			}
		}else{
			return 1;
		}
		
	}

}
